package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type WaterOrder struct {
	ID        string    `gorm:"primaryKey;type:varchar(36);not null;" json:"id"`
	Phone     string    `gorm:"column:phone;type:varchar(11);not null;default:''" json:"phone"`
	Price     int       `gorm:"column:price;type:int;not null;default:0" json:"price"`
	Quantity  int       `gorm:"column:quantity;type:int;not null;default:0" json:"quantity"`
	Status    int       `gorm:"column:status;type:int;not null;default:0" json:"status"`
	Linkman   string    `gorm:"column:link_man;type:varchar(255);default:''" json:"linkman"`
	Address   string    `gorm:"column:address;type:varchar(255);default:''" json:"address"`
	DictId    string    `gorm:"column:dict_id;type:varchar(255);" json:"dictId"`
	Desc      string    `gorm:"column:desc;type:varchar(255);default:''" json:"desc"`
	CreatedAt time.Time `gorm:"type:timestamp" json:"created_at"`
	UpdatedAt time.Time `gorm:"type:timestamp" json:"updated_at"`
}

func (w *WaterOrder) TableName() string {
	return "new_water_order"
}

func (w *WaterOrder) BeforeCreate(tx *gorm.DB) (err error) {
	w.ID = uuid.NewString()
	w.CreatedAt = time.Now()
	w.UpdatedAt = time.Now()
	return
}

func (w *WaterOrder) BeforeUpdate(tx *gorm.DB) (err error) {
	w.UpdatedAt = time.Now()
	return
}
